<script setup lang="ts">
import { Popup } from "vant";
import { ref, onMounted } from "vue";
import { useI18n } from "vue-i18n";
import { HomeAxios } from "@/api";
import { showLoadingToast, closeToast } from "vant";
const popupShow = ref(false);
const { t } = useI18n();
onMounted(() => {
  //初始化 Facebook SDK
  // if ((window as any).FB.init) {
  //   (window as any).FB.init({
  //     appId: "1536163060348583",
  //     autoLogAppEvents: true,
  //     xfbml: true,
  //     version: "v12.0",
  //   });
  // }

  getCustomerConfigList();
});
const firstAidList: any = ref([]);
//获取客服列表
const getCustomerConfigList = () => {
  showLoadingToast({
    message: "",
    forbidClick: true,
  });
  HomeAxios.getCustomerConfigList()
    .then(res => {
      firstAidList.value = res;
      closeToast();
    })
    .finally(() => {
      closeToast();
    });
};
//打开客服页面
const openHtmlUrl = data => {
  window.open(data.url);
};
//打开客服列表
const openActfirst = () => {
  popupShow.value = true;
};
defineExpose({ openActfirst });
</script>
<template>
  <Popup
    v-model:show="popupShow"
    :position="'bottom'"
    z-index="10000"
    duration="0.1"
    style="height: 100%; background-color: rgba(0, 0, 0, 0.25)"
    :overlay="false"
    :safe-area-inset-top="true"
    :safe-area-inset-bottom="true"
  >
    <div class="content-frame">
      <div class="background-frame"></div>
      <div class="div-frame">
        <div class="title-frame df jc-center ai-center">
          <div class="title-name df ai-center">{{ t("navigationBar.firstAid") }}</div>
          <img
            class="close-img"
            src="@/image/new_img/home/cs_close.png"
            @click="popupShow = false"
          />
        </div>
        <div class="act-logo-frame">
          <img class="firstAid-img" src="@/image/new_img/home/pinglun_lan.png" />
          <div class="firstAidTitle">
            {{ t("firstAid.firstAidTitle") }}
          </div>
          <div class="first-frame">
            {{ firstAidList.length }}
            <div
              class="first-content df ai-center jc-space-between"
              v-for="(item, index) in firstAidList.list"
              :key="index"
              @click="openHtmlUrl(item)"
            >
              <div class="df ai-center">
                <img class="logo2-img" src="@/image/new_img/home/logo2.png" />
                <div v-if="item.contactType === 1">
                  <div class="first-name">WhatsApp</div>
                  <div class="first-name-title">WhatsApp：{{ item.name }}</div>
                </div>
                <div v-if="item.contactType === 2">
                  <div class="first-name">Telegram</div>
                  <div class="first-name-title">Telegram：{{ item.name }}</div>
                </div>
                <div v-if="item.contactType === 3">
                  <div class="first-name">Instagram</div>
                  <div class="first-name-title">Instagram：{{ item.name }}</div>
                </div>
                <div v-if="item.contactType === 4">
                  <div class="first-name">Tel</div>
                  <div class="first-name-title">Tel：{{ item.name }}</div>
                </div>
                <div v-if="item.contactType === 5">
                  <div class="first-name">{{ t("firstAid.onlineService") }}</div>
                  <div class="first-name-title">{{ t("firstAid.onlineService") }}</div>
                </div>
              </div>
              <img class="homev2-enable" src="@/image/new_img/home/homev2_chat_enable.png" />
            </div>
          </div>
        </div>
      </div>
    </div>
  </Popup>
</template>
<style scoped lang="less">
.content-frame {
  width: 100%;
  height: 100%;
  position: relative;
  left: 0;
  top: 0;
  overflow-y: scroll;
  ::-webkit-scrollbar {
    display: none;
    overflow: -moz-scrollbars-none; /* Firefox */
    -ms-overflow-style: none; /* IE 和 Edge */
  }
  .background-frame {
    position: absolute;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    z-index: 1;
    background: rgba(0, 0, 0, 0.5);
    /*半透明背景色 */
    backdrop-filter: blur(20px);
    /*背景模糊效果 */
    -webkit-backdrop-filter: blur(20px);
  }
  .div-frame {
    position: absolute;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    z-index: 10;
  }
  .title-frame {
    width: 100%;
    height: 112.5px;
    background: rgba(255, 255, 255, 0.25);
    position: relative;
    left: 0;
    right: 0;
  }

  .title-name {
    font-size: 40px;
    color: #ffffff;
  }
  .close-img {
    width: 46px;
    height: 46px;
    margin-left: 100px;
    position: absolute;
    right: 30px;
    top: 30px;
  }
  .act-logo-frame {
    width: 100%;
    height: calc(100% - 130px);
    text-align: center;
    margin: auto;
    overflow-y: auto;
    &::-webkit-scrollbar {
      display: none;
    }
    .firstAid-img {
      height: 166px;
      width: 166px;
      margin: auto;
      margin-top: 76px;
    }
  }
  .firstAidTitle {
    width: 87%;
    font-size: 26px;
    color: rgba(255, 255, 255, 0.65);
    line-height: 40px;
    margin: auto;
    margin-top: 16px;
    margin-bottom: 36px;
  }
  .first-frame {
    width: calc(100% - 80px);
    margin-left: 40px;
    height: auto;
    .first-content {
      width: 100%;
      height: 172px;
      border-radius: 34px;
      background-image: linear-gradient(
        180deg,
        rgba(255, 255, 255, 0.15) 0%,
        rgba(255, 255, 255, 0) 100%
      );
      border: 1px solid rgba(255, 255, 255, 0.15);
      margin-bottom: 20px;
      .logo2-img {
        width: 100px;
        height: 100px;
        border-radius: 50%;
        margin-left: 20px;
        margin-right: 20px;
      }
      .first-name {
        font-size: 28px;
        color: #ffffffa6;
        text-align: left;
      }
      .first-name-title {
        margin-top: 30px;
        font-size: 24px;
        color: rgba(255, 255, 255, 0.25);
      }
      .homev2-enable {
        width: 100px;
        height: 50px;
        margin-right: 40px;
      }
    }
  }
}
</style>
